using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Emlyn.Website.Users;
using Emlyn.Common.Data.DBUpdater;

public partial class SiteLogin : EmlynPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DBUpdaterMain.WebsiteCode = "EmlynORegan";
    }
    protected void btnGo_Click(object sender, EventArgs e)
    {
        User luser = new User();
        luser.UserName = edUserName.Text;
        luser.SetPassword(edPassword.Text);

        UserQuery luserQuery = new UserQuery();

        try
        {
            luserQuery.CheckCredentials(luser, DBUpdaterMain.WebsiteCode);

            FormsAuthentication.RedirectFromLoginPage(luser.UserName, false);
        }
        catch (UnknownUserException)
        {
            lblError.Text = "Unknown User or Password";
        }
        catch (IncorrectPasswordException)
        {
            lblError.Text = "Unknown User or Password";
        }
        catch (NoWebsiteAccessException)
        {
            lblError.Text = "User does not have access to this website";
        }
        catch (Exception ex)
        {
            lblError.Text = ex.ToString();
        }
    }
}
